import types


def writeTreeToConsole(tree, indentLevel=0):
    if type(tree) == types.ListType:
        line = ""
        for i in range(indentLevel):
            line += "     "
        line += tree[0]
        print line
        writeTreeToConsole(tree[1], indentLevel+1)
        writeTreeToConsole(tree[2], indentLevel+1)
    else:
        line = "     "
        for i in range(indentLevel-1):
            line += "     "
        line += str(tree)
        print line

if __name__ == '__main__':


    import trees
    gp = ['+', ['+',1,['-',3,5]], 4]
    gp2 = trees.generateRandomExpr(['+','-','*','%'],['x',1,2,3],3,'grow')

    writeTreeToConsole(gp2)
